﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace KinectPG.LibraryTestGame
{
    class MenuButton
    {
        private Rectangle ButtonRectangle { get { return rect; } }
        private string buttonText;
        private Rectangle rect;
        private SpriteBatch spriteBatch;
        private Texture2D blank;
        private GraphicsDevice graphics;
        private ContentManager content;
        private SpriteFont font;
        private GameTime startTime;
        private Texture2D btnText;
        private Texture2D btnClickText;

        public delegate void ClickActionDelegate();
        public ClickActionDelegate clickActionDelegate;

        public MenuButton(ContentManager c, GraphicsDevice g, SpriteBatch sb, string text, int x, int y)
        {
            this.buttonText = text;
            this.btnText = c.Load<Texture2D>("btn_menu");
            this.btnClickText = c.Load<Texture2D>("btn_menu_click");
            this.spriteBatch = sb;
            this.graphics = g;
            this.content = c;
            startTime = new GameTime();
            this.font = content.Load<SpriteFont>("SpriteFont1");
            this.blank = new Texture2D(graphics, 1, 1);

            rect = new Rectangle(x, y, 100, 50);
        }

        public void Draw(int x, int y, GameTime gameTime)
        {
            if (x > this.rect.X && x < this.rect.X + this.rect.Width && y > this.rect.Y && y < this.rect.Y + this.rect.Height)
            {
                if (startTime.TotalGameTime != TimeSpan.Zero)
                {
                    if (gameTime.TotalGameTime.Seconds - startTime.TotalGameTime.Seconds >= 5)
                    {
                        clickActionDelegate();
                    }
                }
                else
                {
                    startTime = new GameTime(gameTime.TotalGameTime, gameTime.TotalGameTime);
                }
                spriteBatch.Draw(blank, this.rect, Color.OrangeRed);
                spriteBatch.Draw(btnClickText, this.rect, Color.OrangeRed);
                if (gameTime.TotalGameTime.Seconds - startTime.TotalGameTime.Seconds >= 2)
                    clickActionDelegate();
            }
            else
            {
                //spriteBatch.Draw(blank, this.rect, Color.Orange);
                spriteBatch.Draw(btnText, this.rect, Color.Orange);
            }
            spriteBatch.DrawString(font, this.buttonText, new Vector2(this.rect.X + 10, this.rect.Y + 5), Color.Black);

        }
    }
}
